package com.eeepay.eeepay_v2.adapter;

import android.content.Context;
import android.text.TextUtils;

import com.eeepay.eeepay_v2.R;
import com.eeepay.eeepay_v2.model.ProfitInfo;
import com.eeepay.v2_library.adapter.ABBaseAdapter;
import com.eeepay.v2_library.adapter.ABViewHolder;
import com.eeepay.v2_library.view.HorizontalItemView;

/**
 * Created by zw on 2016/3/14 0014.
 */
public class ProfitListAdapter extends ABBaseAdapter<ProfitInfo>{

    public ProfitListAdapter(Context context) {
        super(context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_profit_info_list;
    }

    @Override
    public void convert(ABViewHolder holder, ProfitInfo model) {
        holder.setRightText(R.id.lrt_service_name, model.getServiceName());

        //银行卡种类：0-不限，1-只信用卡，2-只储蓄卡
        String cardType = "0".equals(model.getCardType()) ? "不限" :
                "1".equals(model.getCardType()) ? "信用卡" : "储蓄卡";
        holder.setRightText(R.id.lrt_card_tyoe, cardType);

        //交易时间：0-不限， 1-只工作日，2-只节假日
        String tradeTime;
        if("0".equals(model.getTradeTime())){
            tradeTime = "不限";
        }else if("1".equals(model.getTradeTime())){
            tradeTime = "工作日";
        }else if("2".equals(model.getTradeTime())){
            tradeTime = "节假日";
        }else {
            tradeTime = "";
        }
        holder.setRightText(R.id.lrt_trade_time, tradeTime);

        if(!TextUtils.isEmpty(model.getInCome())){
            String serviceType = model.getServiceType();//服务类型
            if (serviceType!=null) {
                String value = "";
                if (serviceType.equals("10000") || serviceType.equals("10001"))
                    value = String.format("%s元", model.getInCome());
                else
                    value = String.format("%s", model.getInCome() + "%");

                holder.setHvRightText(R.id.hv_income, value).
                        setHvRightTextColor(R.id.hv_income, mContext.getResources().getColor(R.color.red));
            }
            else
            {
                holder.setHvRightText(R.id.hv_income, model.getInCome()).
                        setHvRightTextColor(R.id.hv_income, mContext.getResources().getColor(R.color.red));
            }
        }
        else
        {
            holder.setHvRightText(R.id.hv_income, "");
        }
        HorizontalItemView hv = holder.getView(R.id.hv_income);
        hv.setLeftText(model.getFlag());

    }
}
